//
//  STFBaseViewController.swift
//  高仿新浪微博
//
//  Created by 沈腾飞 on 2017/1/17.
//  Copyright © 2017年 shen. All rights reserved.
//

import UIKit

class STFBaseViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        print("STFBaseViewController")
    }
    
    
    
    
    
    //判断用户是否登陆
    let isLogin : Bool = true
    //定义访客视图 (全局)
     var baseView : STFBaseView?
    
    override func loadView() {
        if isLogin {//已登录
            view = UITableView ()
        } else {//未登录
//            view = STFBaseView ()
            setUpSTFBaseView()
        }
    }
    
    //实例化STFBaseView(访客视图)
    private func setUpSTFBaseView () {
        
        baseView = STFBaseView ()
        //实例化闭包
        baseView?.block = { [weak self] in
            
            //回调
            print("点击了111111====闭包====")
            self?.loginClick()
           
        }
        
        setupNav()
        
        view = baseView
    }
    //MARK : - 设置导航栏的按钮
    private func setupNav () {
        
        //左边
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(imgName: nil, title: "登陆", target: self, action: #selector(loginClick))
        //右边
        navigationItem.rightBarButtonItem = UIBarButtonItem(imgName: nil, title: "注册", target: self, action: #selector(loginClick))
        
    }
    
    //登陆按钮的监听方法
    
    @objc private func loginClick () {
        
        print("点击了222222-====模态=====")
        
        //模态弹出微博登陆界面
        //实例化一个控制器
        let OauthVc = STFOAuthViewController()
        
        self.present(STFNavigationController(rootViewController: OauthVc), animated: true, completion: nil)
        
    }
    
    
   
    
    
    
    
}
